﻿using System;
using System.Collections.Generic;
using Midi;
using AutomaTones.Model.Automaton_Model;
using Microsoft.Pex.Framework;

namespace AutomaTones.Model.MIDI.Mappers
{
    /// <summary>
    /// 
    /// </summary>
    /// <author>Anders Bech Mellson, anbh@itu.dk</author>
    [PexClass]
    partial class BechTranslator : IMapper
    {
        private readonly List<NoteOut> _notes = new List<NoteOut>();

        [PexMethod]
        public List<NoteOut> Translate(State[,] grid) {
            Random random = new Random();
            _notes.Clear();
            for (int x = 0; x < grid.GetLength(0);x++)
                for (int y = 0; y < grid.GetLength(1); y++)
                    if (grid[x, y].CurrentState > 0) {
                        if (grid[x, y].CurrentState == 1) {
                            _notes.Add(new NoteOut(Pitch.G0, random.Next(128), 50, random.Next(20)));
                            break;
                        }
                        if (grid[x, y].CurrentState == 3) {
                            _notes.Add(new NoteOut(Pitch.F0, random.Next(128), 50, random.Next(20)));
                            break;
                        }
                        if (grid[x, y].CurrentState == 5) {
                            _notes.Add(new NoteOut(Pitch.FSharp0, random.Next(128), 50, random.Next(20)));
                            break;
                        }
                    }
            return _notes;
        }
    }
}
